﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;

namespace Hotel_Management
{
    static public class Walidacja
    {
        public static bool IsFormValid(bool[] formValid)
        {
            var poprawne = formValid.Count(t => t);

            return poprawne == formValid.Length;
        }

        public static bool IsIntegerNumber(TextBox textBox)
        {
            int output;
            return int.TryParse(textBox.Text, out output);
        }

        public static bool IsDoubleNumber(TextBox textBox)
        {
            double output;
            return double.TryParse(textBox.Text, out output);
        }

        public static bool IsPeselValid(TextBox textBox)
        {
            if (IsStringNotEmpty(textBox))
            {
                return Convert.ToInt32(textBox.Text.Length) == 11;
            }
            else return false;
        }

        public static bool IsStringNotEmpty(TextBox textBox)
        {
            return !String.IsNullOrEmpty(textBox.Text);
        }

        public static bool IsLoginExists(string login, List<string> listOfLogins)
        {
            var isExist = true;

            foreach (var t in listOfLogins)
            {
                var replace = t.Replace(" ", string.Empty);
                if (replace != login)
                {
                    isExist = false;
                }
            }

            return isExist;
        }
    }
}